home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * (a) (C) 1990 by Adobe Systems Incorporated. All rights reserved.
- *
- * (b) If this Sample Code is distributed as part of the Display PostScript
- * System Software Development Kit from Adobe Systems Incorporated,
- * then this copy is designated as Development Software and its use is
- * subject to the terms of the License Agreement attached to such Kit.
- *
- * (c) If this Sample Code is distributed independently, then the following
- * terms apply:
- *
- * (d) This file may be freely copied and redistributed as long as:
- * 1) Parts (a), (d), (e) and (f) continue to be included in the file,
- * 2) If the file has been modified in any way, a notice of such
- * modification is conspicuously indicated.
- *
- * (e) PostScript, Display PostScript, and Adobe are registered trademarks of
- * Adobe Systems Incorporated.
- *
- * (f) THE INFORMATION BELOW IS FURNISHED AS IS, IS SUBJECT TO
- * CHANGE WITHOUT NOTICE, AND SHOULD NOT BE CONSTRUED
- * AS A COMMITMENT BY ADOBE SYSTEMS INCORPORATED.
- * ADOBE SYSTEMS INCORPORATED ASSUMES NO RESPONSIBILITY
- * OR LIABILITY FOR ANY ERRORS OR INACCURACIES, MAKES NO
- * WARRANTY OF ANY KIND (EXPRESS, IMPLIED OR STATUTORY)
- * WITH RESPECT TO THIS INFORMATION, AND EXPRESSLY
- * DISCLAIMS ANY AND ALL WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR PARTICULAR PURPOSES AND NONINFRINGEMENT
- * OF THIRD PARTY RIGHTS.
- */
-
- /*
- * PSWpatterns.psw
- *
- * Creator: Carl Orthlieb
- * CreationDate: 90-11-27
- * Modified for DPS by Ken Fromm
- */
-
- defineps PSWPatternDefs ()
-
- %
- % This dictionary is for using the font method of pattern display.
- % It should be used especially for printing because it is much
- % faster than drawing each cell.
- %
- /PatternDict
- 35 dict begin
-
- % PATcg - currentgstate equivalent
- /PATcg {
- 8 dict dup begin
- /lw currentlinewidth def
- /lc currentlinecap def
- /lj currentlinejoin def
- /ml currentmiterlimit def
- /ds [ currentdash ] def
- /cc [ currentrgbcolor ] def
- /cm matrix currentmatrix def
- end
- } bind def
-
- % PATsg - setgstate equivalent
- /PATsg { % dict
- begin
- lw setlinewidth
- lc setlinecap
- lj setlinejoin
- ml setmiterlimit
- ds aload pop setdash
- cc aload pop setrgbcolor
- cm setmatrix
- end
-
- % Translate to the current halftonephase if defined
- PATthtp
- } bind def
-
- % PATthtp - translate to current halftonephase
- % Conditionally define PATthtp. If that currenthalftonephase
- % operator exists, then define a procedure to handle phase
- % shifts i.e. scrolling events, otherwise define it as a null procedure.
- /currenthalftonephase where
- {
- pop
- /PATthtp { % -
- currenthalftonephase % dx dy
- idtransform % x y
- translate % -
- } bind def
- } { /PATthtp { } def } ifelse
-
- % PATsc - setcolor equivalent (takes an array as a parameter instead of loose values)
- /PATsc { % colorarray
- aload length % c1 ... cn length
- dup 1 eq { pop setgray } { 3 eq { setrgbcolor } { setcmykcolor } ifelse } ifelse
- } bind def
-
- % PATtcalc - creates a matrix appropriate for the different tiling types.
- /PATtcalc { % modmtx tilingtype PATtcalc tilematrix
- % Note: tiling type 2 is not currently supported, no adjustment is performed.
- gsave
- exch concat % tilingtype
- matrix currentmatrix exch % cmtx tilingtype
- 2 ne { % Tiling type 1 and 3, constant spacing
- % Distort the pattern so that it occupies an integral number of device pixels
- dup 4 get exch dup 5 get exch % tx ty cmtx
- XStep 0 dtransform round exch round exch % tx ty cmtx dx.x dx.y
- XStep div exch XStep div exch % tx ty cmtx a b
- 0 YStep dtransform round exch round exch % tx ty cmtx a b dy.x dy.y
- YStep div exch YStep div exch % tx ty cmtx a b c d
- 7 -3 roll astore % [ a b c d tx ty ]
- } if
- grestore
- } bind def
-
- % This junk string is used during the pattern fill
- /PATfstr 1 string def
-
- % PATmp - the makepattern equivalent
- /PATmp { % patdict patmtx PATmp -
- exch dup length 13 add % We will add 12 new entries plus 1 FID
- dict copy % Create a new dictionary
- begin
- dup /PatMatrix exch def
-
- % Matrix to install when painting the pattern
- TilingType PATtcalc
-
- /PatternGState PATcg def
- PatternGState /cm 3 -1 roll put
-
- % Check for multiple pattern sources (Level 1 fast colour patterns)
- currentdict /Multi known not { /Multi false def } if
- /NumSources currentdict /PaintColors known { PaintColors length } { 1 } ifelse def
-
- % Width and height of the pattern
- /PatWidth XStep PATfstr length mul def
- /PatHeight YStep def
-
- % Font dictionary definitions
- /FontType 3 def
-
- % Create a dummy encoding vector
- /Encoding 256 array def
- 3 string 0 1 255 { Encoding exch dup 3 index cvs cvn put } for pop
- /FontMatrix matrix def
- /FontBBox BBox def
- /BuildChar {
- mark 3 1 roll % mark dict char
- exch begin
- Multi { PaintData exch get } { pop } ifelse % mark [paintdata]
- PaintType 2 eq Multi or
- { XStep 0 FontBBox aload pop setcachedevice }
- { XStep 0 setcharwidth } ifelse
- currentdict % mark [paintdata] dict
- /PaintProc load % mark [paintdata] dict paintproc
- end
- gsave
- false PATredef exec true PATredef
- grestore
- cleartomark % -
- } bind def
- currentdict
- end % newdict
- /foo exch % /foo newdict
- definefont % newfont
- } bind def
-
- % PATpcalc - calculates the starting point and width/height of the tile fill for the shape
- /PATpcalc { % - PATpcalc nw nh px py
- PATDict /CurrentPattern get begin
- gsave
- % Set up the coordinate system to Pattern Space and lock down pattern
- PatternGState PATsg
- % Translate to the beginning of the pattern cell
- BBox aload pop pop pop translate
-
- % Determine the bounding box of the shape
- pathbbox % llx lly urx ury
- grestore
-
- % Adjust for overlapping patterns
- FontBBox aload pop % llx lly urx ury llx lly urx ury
- 3 -1 roll sub exch % llx lly urx ury llx h urx
- 3 -1 roll sub exch % llx lly urx ury w h
- exch PatWidth div
- ceiling 1 sub PatWidth mul % llx lly urx ury h w'
- exch PatHeight div
- ceiling 1 sub PatHeight mul % llx lly urx ury w' h'
- 5 -1 roll exch sub % llx urx ury w' lly
- 4 1 roll % llx lly urx ury w'
- 5 -1 roll exch sub % lly urx ury llx
- 4 1 roll % llx lly urx ury
-
- % Determine (nw, nh) the number of cells to paint width and height
- PatHeight div ceiling % llx lly urx qh
- 4 1 roll % qh llx lly urx
- PatWidth div ceiling % qh llx lly qw
- 4 1 roll % qw qh llx lly
- PatHeight div floor % qw qh llx ph
- 4 1 roll % ph qw qh llx
- PatWidth div floor % ph qw qh pw
- 4 1 roll % pw ph qw qh
- 2 index sub cvi abs % pw ph qw qh-ph
- exch 3 index sub cvi abs exch % pw ph nw=qw-pw nh=qh-ph
-
- % Determine the starting point of the pattern fill (px, py)
- 4 2 roll % nw nh pw ph
- PatHeight mul % nw nh pw py
- exch % nw nh py pw
- PatWidth mul exch % nw nh px py
- end
- } bind def
-
- % PATfill - performs the tiling for the shape
- /PATfill { % nw nh px py PATfill -
- save 5 1 roll
- PATDict /CurrentPattern get dup begin
- setfont
-
- % Set up the coordinate system to Pattern Space
- PatternGState PATsg
-
- % Set the color for uncolored patterns
- PaintType 2 eq { PATDict /PColor get PATsc } if
-
- 3 index string PatternDict /PATfstr 3 -1 roll put
-
- % Loop for each of the pattern sources
- 0 1 NumSources 1 sub { % nw nh px py source
- % Move to the starting location
- 2 index 2 index % nw nh px py source px py
- moveto % nw nh px py source
-
- % For multiple sources, set the appropriate color
- Multi { dup PaintColors exch get PATsc } if
-
- % Set the appropriate string for the source
- 0 1 6 index 1 sub { % nw nh px py source 0 1 nw-1
- PATfstr exch 2 index put
- } for
- pop % nw nh px py
-
- % Loop over the number of vertical cells
- 2 index % nw nh px py nh
- { % nw nh px py
- % Show a row at a time
- currentpoint % nw nh px py cx cy
- PATfstr show
- YStep add moveto % nw nh px py cx cy
- } repeat
- } for
- pop pop pop pop
- end
- restore
- } bind def
-
- % Save the original routines so that we can use them later on
- /oldfill /fill load def
- /oldeofill /eofill load def
- /oldstroke /stroke load def
- /oldshow /show load def
- /oldashow /ashow load def
- /oldwidthshow /widthshow load def
- /oldawidthshow /awidthshow load def
- /oldkshow /kshow load def
- /oldrectfill /rectfill load def
- /oldrectstroke /rectstroke load def
-
- % These redefinitions are necessary so that subsequent procs don't bind in
- % the originals
- /PATredef {
- userdict begin
- {
- /fill { /clip load PATdraw newpath } bind def
- /eofill { /eoclip load PATdraw newpath } bind def
- /stroke { strokepath /clip load PATdraw newpath } bind def
- /show { 0 0 null 0 0 6 -1 roll PATawidthshow } bind def
- /ashow { 0 0 null 6 3 roll PATawidthshow } bind def
- /widthshow { 0 0 3 -1 roll PATawidthshow } bind def
- /awidthshow { PATawidthshow } bind def
- /kshow { PATkshow } bind def
- /rectfill { PATrectfill newpath } bind def
- /rectstroke { PATrectstroke newpath } bind def
- } {
- /fill { oldfill } bind def
- /eofill { oldeofill } bind def
- /stroke { oldstroke } bind def
- /show { oldshow } bind def
- /ashow { oldashow } bind def
- /widthshow { oldwidthshow } bind def
- /awidthshow { oldawidthshow } bind def
- /kshow { oldkshow } bind def
- /rectfill { oldrectfill } bind def
- /rectstroke { oldrectstroke } bind def
- } ifelse
- end
- } bind def
- false PATredef
-
- % PATdraw - calculates the boundaries of the object and fills it with the current pattern
- /PATdraw { % proc
- PATpcalc % proc nw nh px py
- gsave
- 5 -1 roll exec % nw nh px py
- newpath
- PATfill % -
- grestore
- } bind def
-
- /PATsstr 1 string def % This junk string is used by the show operators
-
- % PATawidthshow - awidthshow with the current pattern
- /PATawidthshow { % cx cy cchar rx ry string
- % Loop over each character in the string
- { % cx cy cchar rx ry ch
- % Show the character
- dup % cx cy cchar rx ry char char
- PATsstr dup 0 4 -1 roll put % cx cy cchar rx ry char (char)
- false charpath % cx cy cchar rx ry char
- /clip load PATdraw
-
- % Move past the character (charpath modified the current point)
- currentpoint % cx cy cchar rx ry char x y
- newpath
- moveto % cx cy cchar rx ry char
-
- % Reposition by cx,cy if the character in the string is cchar
- 3 index eq { % cx cy cchar rx ry
- 4 index 4 index rmoveto
- } if
-
- % Reposition all characters by rx ry
- 2 copy rmoveto % cx cy cchar rx ry
- } forall
- pop pop pop pop pop % -
- newpath
- } bind def
-
- % PATkshow - kshow with the current pattern
- /PATkshow { % proc string
- exch bind % string proc
- 1 index 0 get % string proc char
- % Loop over all but the last character in the string
- 0 1 4 index length 2 sub
- { % string proc char idx
- % Find the n+1th character in the string
- 3 index exch 1 add get % string proc char char+1
- exch 2 copy % string proc char+1 char char+1 char
-
- % Now show the nth character
- PATsstr dup 0 4 -1 roll put % string proc char+1 char char+1 (char)
- false charpath % string proc char+1 char char+1
- /clip load PATdraw
-
- % Move past the character (charpath modified the current point)
- currentpoint newpath moveto
- % Execute the user proc (should consume char and char+1)
- mark 3 1 roll % string proc char+1 mark char char+1
- 4 index exec % string proc char+1 mark ...
- cleartomark % string proc char+1
- } for
-
- % Now display the last character
- PATsstr dup 0 4 -1 roll put % string proc (char+1)
- false charpath % string proc
- /clip load PATdraw
- newpath
- pop pop % -
- } bind def
-
- /PATrectdraw { % x y w h
- 4 2 roll moveto 1 index 0 rlineto
- 0 exch rlineto neg 0 rlineto closepath
- } bind def
-
- /PATrectprocess {
- 1 index type /arraytype eq {
- exch 0 4 2 index length 1 sub {
- dup 3 add 1 exch {1 index exch get exch } for
- 5 1 roll 5 index exec
- } for pop pop
- } { exec} ifelse
- } bind def
-
- % PATrectfill - rectfill with the current pattern
- % IMPORTANT: Does not handle number string arrays.
- /PATrectfill { % x y w h or [[x y w h] ... [x y w h]]
- newpath { PATrectdraw /clip load PATdraw } PATrectprocess
- } bind def
-
- % PATrectstroke - rectstroke with the current pattern
- % IMPORTANT: Does not handle number string arrays.
- /PATrectstroke { % x y w h or [[x y w h] ... [x y w h]] or ... matrix
- newpath
- dup type /arraytype eq {
- dup length 6 eq
- } { false } ifelse
- {{gsave PATrectdraw null concat strokepath /clip load PATdraw grestore}
- dup length array cvx copy dup 2 4 -1 roll put PATrectprocess }
- {{PATrectdraw strokepath /clip load PATdraw} PATrectprocess } ifelse
- } bind def
-
- /PATDict 3 dict def
-
- % PATsp - the setpattern equivalent
- /PATsp { % pattern PATsp -
- true PATredef
- PATDict begin
- /CurrentPattern exch def
-
- % If it's an uncolored pattern, save the color
- CurrentPattern /PaintType get 2 eq {
- /PColor [ currentrgbcolor ] def
- } if
- /CColor [ currentrgbcolor ] def
- end
- } bind def
-
- % PATusp - unsetpattern
- /PATusp {
- false PATredef
- PATDict begin
- CColor aload pop setrgbcolor
- end
- } bind def
-
- % Expand the pattern from a 1 by 1 cell to a cell specified by r and c.
- % Expanding the pattern speeds up the dispaly and printing.
- /PATep { % r c patdict PATmp newpatdict
- dup length dict copy % Create a new dictionary
- begin
- [
- 0 XStep dup 4 index 1 sub mul
- [
- 0 YStep dup 9 index 1 sub mul
- [
- % save the graphics state and translate to
- % the new image position
- 1 /index load /exch load /gsave load /translate load
- % place copies of the data if it exists and the dictionary
- % on the stack
- currentdict /Multi known {
- Multi {
- 2 /index load 2 /index load
- } { 1 /index load } ifelse
- } { 1 /index load } ifelse
- /PaintProc load /exec load
- /grestore load
- ] cvx /for load /pop load
- ] cvx /for load
- /pop load % pop the dict off the stack
- % pop the data off the stack if it exists
- currentdict /Multi known { Multi { /pop load } if } if
- ] cvx /PaintProc exch bind def
-
- % Change the BBox
- BBox 4 array copy dup % r c [...] [...]
- /BBox exch def aload dup % r c llx lly urx ury [...] [...]
- 5 -1 roll dup 5 -1 roll exch sub % r c llx urx [...] [...] lly h
- 7 index 1 sub YStep mul add add % r c llx urx [...] [...] ury
- 3 exch put % r c llx urx [...]
- 3 -1 roll dup 4 -1 roll exch sub % r c [...] llx w
- 3 index 1 sub XStep mul add add % r c [...] urx
- 2 exch put % r c
-
- % Change the XStep and YStep values
- XStep mul /XStep exch def % r
- YStep mul /YStep exch def % -
-
- currentdict
- end % newdict
- } bind def
-
- currentdict
- end
- def
-
- % A dictionary that changes PATsg to use the matrix stored
- % in CurrentMatrix locking the pattern to the view. Should only
- % be used if that behavior is desired. The default is to use just
- % the dictionary above.
- /PatternViewDict
- 5 dict begin
-
- % PATcg - currentgstate equivalent
- /PATcg {
- 9 dict dup begin
- /lw currentlinewidth def
- /lc currentlinecap def
- /lj currentlinejoin def
- /ml currentmiterlimit def
- /ds [ currentdash ] def
- /cc [ currentrgbcolor ] def
- /dm matrix currentmatrix def
- /cm matrix currentmatrix def
- end
- } bind def
-
- % PATsg - setgstate equivalent
- /PATsg { % dict
- begin
- lw setlinewidth
- lc setlinecap
- lj setlinejoin
- ml setmiterlimit
- ds aload pop setdash
- cc aload pop setrgbcolor
-
- dm setmatrix
-
- PATViewDict /CurrentMatrix get % matrix
- 0 0 2 index transform % matrix tx1' ty1'
- 2 index 3 get 0 lt { neg} if % matrix tx1' ty'
- 2 index 0 get 0 lt { exch neg exch } if % matrix tx1' ty'
- translate
- pop % -
-
- PatMatrix TilingType PATtcalc setmatrix
- end
- } bind def
-
- /PATViewDict 1 dict def
-
- % PATspw - sets the pattern in the view
- /PATspv { % PATspw -
- PATViewDict /CurrentMatrix matrix currentmatrix put
- } bind def
-
- currentdict
- end
- def
-
- % A dictionary that changes PATsg to use the matrix stored
- % in CurrentMatrix locking the pattern to the view but allowing
- % it to scale and rotate as the view does. Should only be used
- % if that behavior is desired. The default is to use just the
- % dictionary above.
- /PatternViewScaleDict
- 1 dict begin
-
- % PATsg - setgstate equivalent
- /PATsg { % dict
- begin
- lw setlinewidth
- lc setlinecap
- lj setlinejoin
- ml setmiterlimit
- ds aload pop setdash
- cc aload pop setrgbcolor
-
- PATViewDict /CurrentMatrix get setmatrix
- PatMatrix TilingType PATtcalc setmatrix
- end
- } bind def
-
- currentdict
- end
- def
-
- endps
-
- /*****************************************************
- *
- * The wraps called from the pattern object.
- *
- *****************************************************/
- defineps PSWBeginPattern()
- PatternDict begin
- endps
-
- defineps PSWSetPattern(userobject PatternNum)
- PatternNum PATsp
- endps
-
- defineps PSWUnsetPattern()
- PATusp
- endps
-
- defineps PSWCheckPattern(char *PatternName | boolean *Available)
- false Available
- /PatternName where
- {
- begin
- PatternName type /dicttype eq
- { true Available } if
- end
- } { } ifelse
- endps
-
- defineps PSWMakePattern(char *PatternName; float Matrix[6])
- PatternName Matrix PATmp
- endps
-
- /*
- * Expands the pattern from 1 image per cell to an R by C matrix.
- * Assumes the PatternDict is already on the dictionary stack.
- */
- defineps PSWExpandPattern(char *PatternName; float Matrix[6]; int R, C)
- R C PatternName PATep Matrix PATmp
- endps
-
-
- /*
- * These wraps set the state to lock the pattern to the window.
- * The first approach locks the location where the pattern tiles
- * as well as the scale. The pattern appears the same size
- * regardless of the scale of the view.
- *
- * The second approach just locks the location to the view but
- * allows the scale to vary which means the pattern cells get
- * larger and smaller with the scale of the view.
- */
- defineps PSWBeginPatternView()
- PatternViewDict begin
- endps
-
- defineps PSWBeginPatternViewScale()
- PatternViewScaleDict begin
- endps
-
- defineps PSWSetPatternView()
- PatternViewDict begin
- PATspv
- end
- endps
-
-